/*
 * Copyright 2020-2025 the original author or authors.
 * You cannot use this file unless authorized by the author.
 */
package org.ipig.commons.conf.spike;

import com.aerospike.client.Host;
import com.aerospike.client.policy.ClientPolicy;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * SpikeConf
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id: SpikeConf.java 8 2020-04-08 07:44:08Z ts <comchnts@163.com> $$
 * @since 1.0
 */
@Data
@ToString
public class SpikeConf extends ClientPolicy implements Serializable {
    //命名空间
    public static final String KEY_NAMESPACE = "KEY_NAMESPACE";
    //集合
    public static final String KEY_SET = "KEY_SET";
    /**
     * 连接字段串,多个地址以逗号隔开
     */
    private String servers;
    //默认命名空间
    private String defNs;
    // 其它属性
    private Map<String, String> props = new HashMap<String, String>();

    public Host[] getHosts() {
        String[] servers = getServers().split(",");
        int argsLength = servers.length;
        Host[] hosts = new Host[argsLength];
        for (int i = 0; i < argsLength; i++) {
            String host = servers[i].split(":")[0];
            int port = Integer.parseInt(servers[i].split(":")[1]);
            hosts[i] = new Host(host, port);
        }
        return hosts;
    }
}
